package cn.dao.imp;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import cn.dao.OrdersDao;
import cn.entity.Ordergoods;
import cn.entity.Orders;

public class OrdersDaoImp extends HibernateDaoSupport implements OrdersDao {

	@Override
	public void insert(Orders orders) {
		getHibernateTemplate().save(orders);

	}

	@Override
	public void delete(Orders orders) {
		getHibernateTemplate().delete(orders);

	}

	@Override
	public void update(Orders orders) {
		getHibernateTemplate().update(orders);

	}

	public List<Orders> getAll() {
		return getHibernateTemplate().find("from Orders");
	}
	
	//通过时间查询已完成订单
	public List<Orders> queryCompleteByDate(String begin,String end) {
		return getHibernateTemplate().find("from Orders where status='004' and creDate between '"+begin+"' and '"+end+"'");
	}

	@Override
	public Orders getOrdersById(Integer id) {
		return getHibernateTemplate().get(Orders.class, id);
	}

	@Override
	public List<Orders> getOrdersListByBuyer(Integer id) {
		return getHibernateTemplate().find("from Orders where buyer="+id);
	}
	
	@Override
	public List<Orders> getOrdersByOrderNum(String num){
		return getHibernateTemplate().find("from Orders where num='"+num+"'");
	}
	
	@Override
	public List<Ordergoods> getOrdergoodsByOrderId(int id){
		return getHibernateTemplate().find("from Ordergoods where oid="+id);
	}
}
